
package urbanparks;

import java.util.ArrayList;
import java.util.List;
/**
 * This class hold the information for a specific job grade assigned to a job. It holds
 * a list of email addresses for volunteers signed up. 
 * @author Ben Hadorn
 * @version Winter 2012
 */
public class JobGrade {
  /**
   * the description of the JobGrade.
   */
  private String my_description;
  /**
   * the maximum number of people that can be signed up for this job grade.
   */
  private int my_max;
  /**
   * a list of volunteer email addresses for those signed up for this job grade.
   */
  private List<String> my_signup_list = new ArrayList<String>();
  /**
   * the difficulty of the job grade.
   */
  private String my_difficulty;

  /**
   * a constructor that is passed the job difficulty, description and maximum number of people allowed to signup
   * for this job grade.
   * @param the_difficulty
   * @param the_description
   * @param the_max
   */
  public JobGrade(final String the_difficulty,
      final String the_description, final int the_max) {
    my_description = the_description;
    my_difficulty = the_difficulty;
    my_max = the_max;
  }
  /**
   * if added the user would not exceed the maximum allowed volunteers for the job grade, add their
   * email to the list. If it would exceed the maximum return false.
   * @param the_user the email address associated with the user.
   * @return a boolean true if added and false otherwise.
   */
  public boolean addUserToGrade(final String the_user) {
    boolean added = false;
    if (my_signup_list.size() + 1 <= my_max) {
      my_signup_list.add(the_user);
      added = true;
    }
    return added;
  }
  /**
   * if a user unsigns for a job find their email address and remove it from the list
   * @param the_user the email address associated with the user.
   * @return a boolean true if the user was removed and false if the user wansn't. This could only happen
   * if the user wasn't on the list to begin with.
   */
  public boolean removeUserFromGrade(final String the_user) {
    boolean reduced = false;
    if (!my_signup_list.isEmpty() &&
        my_signup_list.contains(the_user)) {
      my_signup_list.remove(the_user);
      reduced = true;
    }
    return reduced;
  }
  /**
   * returns the list of email addresses associated with this job grade.
   * @return a list of strings.
   */
  public List<String> getUserList() {
    return my_signup_list;
  }
  /**
   * a getter for the job description
   * @return String
   */
  public String getDescription() {
    return my_description;
  }
  /**
   * getter for max volunteers allowed
   * @return int
   */
  public int getMaxNeeded() {
    return my_max;
  }
  /**
   * overrides toString method to return only the jobs difficulty.
   */
  @Override
  public String toString() {
    return my_difficulty;
  }
  /**
   * gets the remaining volunteers needed for the job grade.
   * @return int representing the remaining number of volunteers needed.
   */
  public int getCurrentNeeded() {
    return my_max - my_signup_list.size();
  }
}
